﻿@using Blazorise.Localization

<Bar @bind-Visible="@topbarVisible" Breakpoint="Breakpoint.Desktop" Background="Background.Primary" ThemeContrast="ThemeContrast.Light">
    <BarBrand>
        <BarItem>
            <BarLink To="">
                <BarIcon IconName="IconName.Dashboard" />
                Blazorise Demo
            </BarLink>
        </BarItem>
    </BarBrand>
    <BarToggler />
    <BarMenu>
        <BarStart>
            <BarItem>
                <BarLink To="https://blazorise.com/">Home</BarLink>
            </BarItem>
            <BarItem>
                <BarLink To="https://blazorise.com/docs/">Documentation</BarLink>
            </BarItem>
            <BarItem>
                <BarDropdown>
                    <BarDropdownToggle>More</BarDropdownToggle>
                    <BarDropdownMenu>
                        <BarDropdownItem To="https://blazorise.com/docs/quick-start/">
                            Quick-Start Guide
                        </BarDropdownItem>
                        <BarDropdownDivider />
                        <BarDropdownItem To="https://blazorise.com/docs/usage/">
                            Usage
                        </BarDropdownItem>
                    </BarDropdownMenu>
                </BarDropdown>
            </BarItem>
            <BarItem>
                <BarDropdown>
                    <BarDropdownToggle>Layout</BarDropdownToggle>
                    <BarDropdownMenu>
                        <BarDropdownItem Clicked="@(()=>OnLayoutTypeChecked("fixed-header"))">
                            @if ( LayoutType == "fixed-header" )
                            {
                                <Icon Name="IconName.CheckCircle" TextColor="TextColor.Success" />
                            }
                            Fixed Header
                        </BarDropdownItem>
                        <BarDropdownItem Clicked="@(()=>OnLayoutTypeChecked("fixed-header-footer-only"))">
                            @if ( LayoutType == "fixed-header-footer-only" )
                            {
                                <Icon Name="IconName.CheckCircle" TextColor="TextColor.Success" />
                            }
                            Fixed Header and Footer only
                        </BarDropdownItem>
                        <BarDropdownItem Clicked="@(()=>OnLayoutTypeChecked("sider-with-header-on-top"))">
                            @if ( LayoutType == "sider-with-header-on-top" )
                            {
                                <Icon Name="IconName.CheckCircle" TextColor="TextColor.Success" />
                            }
                            Sider with Header on top
                        </BarDropdownItem>
                    </BarDropdownMenu>
                </BarDropdown>
            </BarItem>

            <BarItem>
                <BarDropdown>
                    <BarDropdownToggle>Level1</BarDropdownToggle>
                    <BarDropdownMenu>
                        <BarDropdownItem>Level1.1</BarDropdownItem>
                        <BarDropdown>
                            <BarDropdownToggle>Level2</BarDropdownToggle>
                            <BarDropdownMenu>
                                <BarDropdownItem>Level2.1</BarDropdownItem>
                                <BarDropdown>
                                    <BarDropdownToggle>Level3</BarDropdownToggle>
                                    <BarDropdownMenu>
                                        <BarDropdownItem>Level3.1</BarDropdownItem>
                                    </BarDropdownMenu>
                                </BarDropdown>
                            </BarDropdownMenu>
                        </BarDropdown>
                    </BarDropdownMenu>
                </BarDropdown>
            </BarItem>

        </BarStart>
        <BarEnd>
            <BarItem>
                <BarDropdown RightAligned="true">
                    <BarDropdownToggle><Icon Name="IconName.Language" /></BarDropdownToggle>
                    <BarDropdownMenu>
                        @foreach ( var cultureInfo in LocalizationService.AvailableCultures )
                        {
                            <BarDropdownItem @key="@cultureInfo.Name" Clicked="@(()=>SelectCulture(cultureInfo.Name))">
                                @if ( cultureInfo.IsNeutralCulture )
                                {
                                    @cultureInfo.EnglishName
                                }
                                else
                                {
                                    @cultureInfo.Parent.EnglishName
                                }
                            </BarDropdownItem>
                        }
                    </BarDropdownMenu>
                </BarDropdown>
            </BarItem>
            <BarItem>
                <BarDropdown RightAligned="true">
                    <BarDropdownToggle><Icon Name="IconName.Tint" /> Theme</BarDropdownToggle>
                    <BarDropdownMenu Style="padding: 15px; min-width:550px;">
                        <Row>
                            <Column Margin="Margin.Is2.FromBottom">
                                <Field>
                                    <Switch TValue="bool" Checked="@(Theme?.Enabled == true)" CheckedChanged="@ThemeEnabledChanged">Theme enabled</Switch>
                                </Field>
                            </Column>
                        </Row>
                        <Row>
                            <Column Margin="Margin.Is2.FromBottom">
                                <Field>
                                    <Check TValue="bool" Checked="@(Theme?.IsGradient == true)" CheckedChanged="@ThemeGradientChanged">Gradient colors</Check>
                                </Field>
                                <Field>
                                    <Check TValue="bool" Checked="@(Theme?.IsRounded == true)" CheckedChanged="@ThemeRoundedChanged">Rounded elements</Check>
                                </Field>
                            </Column>
                        </Row>
                        <Row>
                            <Column>
                                <Container Fluid="true">
                                    <ThemeColorSelector Value="@(Theme?.ColorOptions?.Primary)" ValueChanged="@ThemeColorChanged"></ThemeColorSelector>
                                </Container>
                            </Column>
                        </Row>
                    </BarDropdownMenu>
                </BarDropdown>
            </BarItem>
            <BarItem>
                <BarLink To="https://github.com/Megabit/Blazorise">GitHub</BarLink>
            </BarItem>
        </BarEnd>
    </BarMenu>
</Bar>
@code {
    protected override async Task OnInitializedAsync()
    {
        await SelectCulture( "en-US" );

        await base.OnInitializedAsync();
    }

    Task SelectCulture( string name )
    {
        LocalizationService.ChangeLanguage( name );

        return Task.CompletedTask;
    }

    private bool topbarVisible = false;

    Task OnLayoutTypeChecked( string layoutType )
    {
        LayoutType = layoutType;

        return LayoutTypeChanged.InvokeAsync( layoutType );
    }

    [Parameter] public EventCallback<bool> ThemeEnabledChanged { get; set; }

    [Parameter] public EventCallback<bool> ThemeGradientChanged { get; set; }

    [Parameter] public EventCallback<bool> ThemeRoundedChanged { get; set; }

    [Parameter] public EventCallback<string> ThemeColorChanged { get; set; }

    [Parameter] public string LayoutType { get; set; }

    [Parameter] public EventCallback<string> LayoutTypeChanged { get; set; }

    [Inject] protected ITextLocalizerService LocalizationService { get; set; }

    [CascadingParameter] protected Theme Theme { get; set; }
}